home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / mpss / auto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-20  |  3.1 KB  |  125 lines

  1. /*******************************************************************************
  2. ********************************************************************************
  3. ********************************************************************************
  4.  
  5. PERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
  6. THIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
  7.  
  8.         P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
  9.  
  10.  
  11. ********************************************************************************
  12. ********************************************************************************
  13. *******************************************************************************/
  14.  
  15. #include "header.h"
  16.  
  17. lock_on(cp,chno) 
  18. register struct player *cp;
  19. int chno;
  20. {
  21. register struct player *x;
  22. int lockok;
  23.  
  24. lockok=OFF;
  25. x=startlist;
  26. while (x!=NULL)
  27. {
  28.     if (x==cp) {x=x->next; continue;}
  29.     if ((cp->xpos==x->xpos)&&(cp->ypos==x->ypos))
  30.         {
  31.         cp->channel[chno].enemy=x;
  32.         cp->channel[chno].xloc=0;
  33.         cp->channel[chno].yloc=0;
  34.         lockok=ON;
  35. plot1(cp,"        Tractor beam locked onto enemy captain!          ");
  36. plot2(cp,"                                                         ");
  37.         x=NULL;
  38.         } else
  39.         x=x->next;
  40. }
  41. if (lockok==OFF)
  42.     {
  43.     cp->channel[chno].enemy=NULL;
  44.     cp->channel[chno].xloc=cp->xpos;
  45.     cp->channel[chno].yloc=cp->ypos;
  46.     if (inuniv(cp->xpos,cp->ypos)=='*')
  47.     {
  48. plot1(cp,"         Tractor beam locked onto starbase captain!      ");
  49. plot2(cp,"                                                         ");
  50.     } else
  51.     {
  52. plot1(cp,"    Tractor beam locked onto this quadrant captain!      ");
  53. plot2(cp,"                                                         ");
  54.     }
  55.     }
  56.     
  57. }
  58.  
  59. displaybeams(cp) 
  60. register struct player *cp;
  61. {
  62. char str[7];
  63. int i;
  64. poscurs(cp,23,22);
  65. for (i=0; i<4; i++)
  66. {
  67. sprintf(str,"%1d)",(i+1));
  68. write(cp->fd,str,2);
  69. if (cp->channel[i].enemy==NULL)
  70.     {
  71.     if (inuniv(cp->channel[i].xloc,cp->channel[i].yloc)=='*')
  72.         write(cp->fd,"*:",2);
  73.     sprintf(str,"%3d,",cp->channel[i].xloc);
  74.     write(cp->fd,str,4);
  75.     sprintf(str,"%3d ",cp->channel[i].yloc);
  76.     write(cp->fd,str,4);
  77.     } else
  78.     {
  79.     sprintf(str,"%1c:",cp->channel[i].enemy->id);
  80.     write(cp->fd,str,2);
  81.     sprintf(str,"%3d,",cp->channel[i].enemy->xpos);
  82.     write(cp->fd,str,4);
  83.     sprintf(str,"%3d ",cp->channel[i].enemy->ypos);
  84.     write(cp->fd,str,4);
  85.     }
  86. }
  87. }
  88.  
  89. auto_pilot(cp)
  90. register struct player *cp;
  91. {
  92. int x;
  93. x=cp->flyto;
  94. if (cp->channel[x].enemy==NULL)
  95. {
  96. if (cp->xpos!=cp->channel[x].xloc)
  97.         {
  98.         if (cp->xpos<cp->channel[x].xloc) cp->xvel=1; else cp->xvel= -1;        } else cp->xvel=0;
  99. if (cp->ypos!=cp->channel[x].yloc)
  100.         {
  101.         if (cp->ypos<cp->channel[x].yloc) cp->yvel=1; else cp->yvel= -1;
  102.         } else cp->yvel=0;
  103. } else
  104. {
  105. if (cp->xpos!=cp->channel[x].enemy->xpos)
  106.         {
  107.     if (cp->xpos<cp->channel[x].enemy->xpos) cp->xvel=1; else cp->xvel= -1;
  108.         } else cp->xvel=0;
  109. if (cp->ypos!=cp->channel[x].enemy->ypos)
  110.         {
  111.     if (cp->ypos<cp->channel[x].enemy->ypos) cp->yvel=1; else cp->yvel= -1;
  112.         } else cp->yvel=0;
  113. }
  114.  
  115. /* arrival at location*/
  116. if ((cp->xvel==0)&&(cp->yvel==0))
  117.     {
  118.     plotstatus(cp,3);
  119.     cp->flyto= -1;
  120.     plot1(cp," Sulu : We have arrived at the programmed location Sir.  ");
  121.     plot2(cp,"                                                         ");
  122.     }
  123. }
  124.  
  125.